﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;

namespace Gonte.Compiler
{
    public static class ExpressionCompiler
    {
        public static CompilerResults Compile(string source)
        {
            CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");

            CompilerParameters compilerParameters = new CompilerParameters();

            //add assemblies
            compilerParameters.ReferencedAssemblies.Add("System.dll");
            //compilerParameters.ReferencedAssemblies.Add(functionType.Assembly.Location);
            //don't generate assembly on disk and treat warnings as errors
            compilerParameters.GenerateInMemory = true;
            compilerParameters.TreatWarningsAsErrors = true;

            return codeProvider.CompileAssemblyFromSource(compilerParameters, source);
        }
    }
}
